package com.lagou.providerb.config;


import com.alibaba.dubbo.config.*;
import com.lagou.service.HelloService;
import com.lagou.service.HiService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DubboConfig {

    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("provider-B");
        return applicationConfig;
    }

    //<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"></dubbo:registry>
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("127.0.0.1:2181");
        return registryConfig;
    }

    //<dubbo:protocol name="dubbo" port="20881"></dubbo:protocol>
    @Bean
    public ProtocolConfig protocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20882);
        return protocolConfig;
    }

    @Bean
    public ServiceConfig<HiService> hiServiceServiceConfig(HiService hiService) {
        ServiceConfig<HiService> serviceConfig = new ServiceConfig<>();
        serviceConfig.setInterface(HiService.class);
        serviceConfig.setRef(hiService);
        serviceConfig.setVersion("1.0.0");
        return serviceConfig;
    }

    //	<dubbo:provider timeout="1000"></dubbo:provider>
    @Bean
    public ProviderConfig providerConfig() {
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setTimeout(5000);
        return providerConfig;
    }

    //	<dubbo:monitor address="127.0.0.1:7070"></dubbo:monitor>
    @Bean
    public MonitorConfig monitorConfig() {
        MonitorConfig monitorConfig = new MonitorConfig();
        monitorConfig.setAddress("127.0.0.1:7071");
        monitorConfig.setProtocol("registry");
        return monitorConfig;
    }
}
